#'
#'
#'
#' @description a function in the chapter 2. dynamics if shock is known in advance.
#' Z_t is known in period t=0. Based on (2.14) in the chapter 2 in the Heer (2019).
#'
#'  @param x capital stock in the current period, kt.
#'
#'
dynamics1 <- function(x, alpha = 0.36, delta = 0.08, n = 0, beta0 = 0.96, sigma = 2){
  # local nperiod,y,i,c1,c2,r1;
  nperiod <- length(x)
  y <- zeros(nperiod,1)
  i <- 0
  while (i < nperiod){
    i <- i+1
    # Euler eqs in period t
    if (i == 1){
      c2 <- production(zt[i],x[i])+(1-delta)*x[i]-(1+n)*x[i+1]
      c1 <- production(1,kss)+(1-delta)*kss-(1+n)*x[i]
      r1 <- alpha*zt[i]*x[i]^(alpha-1)
      y[i] <- (c2/c1)^(sigma)-beta0*(1+r1-delta)
    } else if (i == nperiod){
      c2 <- production(zt[i],x[i])+(1-delta)*x[i]-(1+n)*kss
      c1 <- production(zt[i-1],x[i-1])+(1-delta)*x[i-1]-(1+n)*x[i]
      r1 <- alpha*zt[i]*x[i]^(alpha-1)
      y[i] <- (c2/c1)^(sigma)-beta0*(1+r1-delta)
    } else {
      c2 <- production(zt[i],x[i])+(1-delta)*x[i]-(1+n)*x[i+1]
      c1 <- production(zt[i-1],x[i-1])+(1-delta)*x[i-1]-(1+n)*x[i]
      r1 <- alpha*zt[i]*x[i]^(alpha-1)
      y[i] <- (c2/c1)^(sigma)-beta0*(1+r1-delta)
    }
  }
  return(y)
}
